"""
序列化器
"""
from datetime import datetime
from rest_framework import serializers


class HttpSerializer(serializers.Serializer):

    def validate(self, attrs):
        return attrs


class PostSerializer(serializers.Serializer):
    # data_field = serializers.DateField(source='date_source',)
    date_time = serializers.DateTimeField(default=datetime.now)


class ItemSerializer(serializers.Serializer):
    char_field = serializers.CharField(max_length=5)

    def validate(self, attrs):
        if not attrs.get('char_field').isalpha():
            raise serializers.ValidationError({
                'char_field': "char_field has number, need alpha."
            })
        return attrs


class ListSerializer(serializers.Serializer):
    list_field = serializers.ListField(child=ItemSerializer(), required=True, allow_empty=False)
